﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using WebSysCore.JSons;
using WebSysCore;
using WebSysCore.Helpers;
using HSchSchedule.Utils;

namespace HSchSchedule.AjaxPages
{
    public partial class AjaxAddSchedule : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod(true)]
        public static string AddSchedule(JListSchedule jls)
        {
            int cusId;
            int.TryParse(HttpContext.Current.Session[GUIConstants.CUSTOMERID_SESSION].ToString(), out cusId);
            if (cusId > 0)
            {
                string err;
                if (ValidateHelp.ValidateSchedule(jls, out err))
                {
                    ListSchedule ls = new ListSchedule();
                    ls.ScheduleName = jls.ScheduleName;
                    ls.CustomerId = cusId;
                    ls.InputDay = DateTime.Now;
                    int currentSchedule = DataBase.AddSchedule(ls);
                    HttpContext.Current.Session[GUIConstants.CURRENTSCHEDULE_SESSION] = currentSchedule;
                    return GUIConstants.SUCCESS_RESULT;
                }
                else
                {
                    return GUIConstants.FAIL_RESULT;
                }
            }
            else
            {
                return GUIConstants.SESSIONCLOSE_RESULT;
            }
        }
    }
}
